package sctu.edu.java.year2016.team01.lishuai.day20160601.chapter10_2;

import java.util.*;

/**
 * Created by 李大帅 on 2016/6/1.
 * 分别向set集合以及list集合中添加“A”，“a”,"c","C","a"5个元素，观察重复值"a"
 * 能否在List集合以及Set集合中成功添加
 */
public class DuplicateValues {

    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();

        String a = "A",b = "a",c = "c",d = "C",e = "a";
        list.add(a);
        list.add(b);
        list.add(c);
        list.add(d);
        list.add(e);
        System.out.println("list集合元素的长度为：" + list.size());
        if(list.size()==5)
        {
            System.out.println("list集合允许重复值");
        }
        else
        {
            System.out.println("List集合不允许重复值");
        }
        Iterator<String> li = list.iterator();
        while (li.hasNext())
        {
            System.out.print(" " + li.next() + " ");
        }
        System.out.println();

        Set<String> set = new HashSet<String>();

        set.add(a);
        set.add(b);
        set.add(c);
        set.add(d);
        set.add(e);

        System.out.println("set的集合元素的长度为：" + set.size());
        if(set.size()==5)
        {
            System.out.println("set集合允许重复值");
        }
        else
        {
            System.out.println("set集合不允许重复值");
        }
        Iterator<String> st=set.iterator();
        while(st.hasNext())
        {
            System.out.print(" " + st.next() + " ");
        }
    }
}

